// Copyright (c) MatrixFramework. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;

namespace MatrixFramework.Photos.Domain.Entities;

/// <summary>
/// 照片相册关联实体
/// </summary>
public class PhotoAlbum : FullAuditedEntity<Guid>, IMultiTenant
{
    /// <summary>
    /// 租户ID
    /// </summary>
    public virtual Guid? TenantId { get; protected set; }

    /// <summary>
    /// 照片ID
    /// </summary>
    public virtual Guid PhotoId { get; protected set; }

    /// <summary>
    /// 相册ID
    /// </summary>
    public virtual Guid AlbumId { get; protected set; }

    /// <summary>
    /// 在相册中的排序
    /// </summary>
    public virtual int SortOrder { get; protected set; }

    /// <summary>
    /// 添加时间
    /// </summary>
    public virtual DateTime AddedAt { get; protected set; }

    /// <summary>
    /// 添加者ID
    /// </summary>
    public virtual Guid? AddedBy { get; protected set; }

    /// <summary>
    /// 备注
    /// </summary>
    [MaxLength(500)]
    public virtual string? Notes { get; protected set; }

    /// <summary>
    /// 关联照片
    /// </summary>
    public virtual Photo Photo { get; protected set; } = null!;

    #region 构造函数

    /// <summary>
    /// 参数化构造函数
    /// </summary>
    /// <param name="id">关联ID</param>
    /// <param name="tenantId">租户ID</param>
    /// <param name="photoId">照片ID</param>
    /// <param name="albumId">相册ID</param>
    /// <param name="sortOrder">排序</param>
    /// <param name="addedBy">添加者</param>
    public PhotoAlbum(
        Guid id,
        Guid? tenantId,
        Guid photoId,
        Guid albumId,
        int sortOrder = 0,
        Guid? addedBy = null) : base(id)
    {
        TenantId = tenantId;
        PhotoId = photoId;
        AlbumId = albumId;
        SortOrder = sortOrder;
        AddedAt = DateTime.UtcNow;
        AddedBy = addedBy;
    }

    /// <summary>
    /// 无参构造函数（用于EF Core）
    /// </summary>
    protected PhotoAlbum()
    {
    }

    #endregion

    #region 业务方法

    /// <summary>
    /// 更新排序
    /// </summary>
    /// <param name="sortOrder">新排序</param>
    public virtual void UpdateSortOrder(int sortOrder)
    {
        SortOrder = sortOrder;
    }

    /// <summary>
    /// 更新备注
    /// </summary>
    /// <param name="notes">备注</param>
    public virtual void UpdateNotes(string notes)
    {
        Notes = notes;
    }

    #endregion
}